﻿@{
    ViewBag.Title = "StatisticalAnalysisList";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}


<script type="text/javascript">
    $(function () {
        $('#ContractType').combobox({
            editable: false, panelHeight: "auto",
            valueField: "DictionaryName",
            textField: "DictionaryName",
            url: "/Dictionary/GetDictionaryByTypeTag?typeTag=ContractType",
            onLoadSuccess: function () {
                var data = $('#ContractType').combobox('getData');
                if (data.length > 0) {
                    $('#ContractType').combobox('select', data[0]["DictionaryName"]);
                }
            },
            onSelect: function (record) {
                var projectID = $("#ProjectID").combobox('getValue');
                initContract(projectID, record.DictionaryName);
            }
        });

        $("#ProjectID").combobox({
            editable: false, panelHeight: "auto",
            valueField: 'ID',
            textField: 'ProjectName',
            url: '/ProjectInfo/ProjectInfoListForFlow',
            onLoadSuccess: function () {
                var data = $("#ProjectID").combobox('getData');
                if (data.length > 0) {
                    $("#ProjectID").combobox('select', data[0]["ID"]);
                }
            },
            onSelect: function (record) {
                var contractType = $("#ContractType").combobox('getValue');
                initContract(record.ID, contractType);
            }
        });

        $("#Year").combobox({
            editable: false, panelHeight: "auto",
            valueField: "DictionaryName",
            textField: "DictionaryName",
            url: "/Dictionary/GetDictionaryByTypeTag?typeTag=Year",
            onLoadSuccess: function () {
                var data = $("#Year").combobox('getData');
                if (data.length > 0) {
                    $("#Year").combobox('select', data[0]["DictionaryName"]);
                }
            }
        });

        $("#Month").combobox({
            editable: false, panelHeight: "auto", multiple: true, separator: ',',
            valueField: "DictionaryName",
            textField: "DictionaryName",
            url: "/Dictionary/GetDictionaryByTypeTag?typeTag=Month",
            onLoadSuccess: function () {
                var  monthArr = new Array();
                var data = $("#Month").combobox('getData');
                if (data.length > 0) {
                    for (var i = 0; i < data.length; i++) {
                        monthArr[i] = data[i]["DictionaryName"];
                    }
                }
                $("#Month").combobox('setValues', monthArr);
            }
        });
    });

    function initContract(projectID, contractType) {
        $("#ContractID").combobox({
            editable: false, panelHeight: "auto", multiple: true, separator: ',',
            valueField: 'ID',
            textField: 'ContractName',
            url: '/ContractInfo/ContractInfoListByProjectIDAndType?projectID=' + projectID + '&contractType=' + encodeURI(contractType),
            onLoadSuccess: function () {
                //var contractIDArr = new Array();
                var data = $("#ContractID").combobox('getData');
                if (data.length > 0) {
                    //for (var i = 0; i < data.length; i++) {
                    //    contractIDArr[i] = data[i]["ID"];
                    //}
                    $("#ContractID").combobox('select', data[0]["ID"]);
                }
                //$("#ContractID").combobox('setValues', contractIDArr);
            }
        });
    }

    function Search() {
        var projectID = $("#ProjectID").combobox('getValue');
        var contractType = $("#ContractType").combobox('getValue');
        var year = $("#Year").combobox('getValue');
        var monthStr = $("#Month").combobox('getValues').toString();
        var contractIDStr = $("#ContractID").combobox('getValues').toString();
        var url = '/MonthPlan/GetStatisticalAnalysisList?projectID=' + projectID + '&contractType=' + encodeURI(contractType) + '&year=' + year + '&monthStr=' + monthStr + '&contractIDStr=' + contractIDStr;
        initTable(url);
    }

    function initTable(dataUrl) {
        $('#statisticalAnalysisGrid').datagrid({
            url: dataUrl,
            iconCls: 'icon-bricks',
            nowrap: true,//当数据长度超出列宽时将会自动截取
            autoRowHeight: false,
            striped: true,//设置为true将交替显示行背景
            collapsible: true,
            pagination: true,
            pageSize: 20,
            remoteSort: false,
            idField: 'ContractID',//表明该列是一个唯一列。
            singleSelect: true,
            fitColumns: true,
            columns:
            [
                [
                    { title: 'ContractID', field: 'ContractID', hidden: true },
                    { title: '标段名称', field: 'ContractName', align: 'center', rowspan: 2, width: 100 },
                    { title: '单位', field: 'Unit', align: 'center', rowspan: 2, width: 50 },
                    { title: '总金额', field: 'TotalMoneyNum', align: 'center', rowspan: 2, width: 100 },
                    { title: '年度计划', field: 'YearPlanMoneyNum', align: 'center', rowspan: 2, width: 100 },
                    { title: '（对应所选月）计划', field: 'CurrentMonthPlanMoneyNum', align: 'center', rowspan: 2, width: 100 },
                    { title: '（对应所选年月）完成', field: '', colspan: 4, width: 400 },
                    { title: '开工累计完成', field: '', colspan: 2, width: 200 }
                ],
                [
                     { title: '金额', field: 'CurrentMonthActualCompletedMoneyNum', align: 'center', width: 100 },
                     { title: '占总金额%', field: 'CurrentMonthActualCompletedTotalProportion', align: 'center', width: 100 },
                     { title: '占年计划%', field: 'CurrentMonthActualCompletedYearProportion', align: 'center', width: 100 },
                     { title: '占月计划%', field: 'CurrentMonthActualCompletedMonthProportion', align: 'center', width: 100 },

                     { title: '金额', field: 'ConstructionCompletedMoneyNum', align: 'center', width: 100 },
                     { title: '占总金额%', field: 'ConstructionCompletedTotalProportion', align: 'center', width: 100 }
                ]
            ],
            onClickRow: function (rowIndex, rowData) {
                var projectID = $("#ProjectID").combobox('getValue');
                var contractType = $("#ContractType").combobox('getValue');
                var year = $("#Year").combobox('getValue');
                var monthStr = $("#Month").combobox('getValues').toString();
                var url = '/MonthPlan/GetStatisticalAnalysisDetailList?projectID=' + projectID + '&contractType=' + encodeURI(contractType) + '&year=' + year + '&monthStr=' + monthStr + '&contractID=' + rowData.ContractID;
                initDetailTable(url);
            },
            onLoadSuccess: function (data) {
                if (data.rows.length > 0) {
                    $('#statisticalAnalysisGrid').datagrid('selectRow', 0);
                    var row = $("#statisticalAnalysisGrid").datagrid("getSelected");
                    var projectID = $("#ProjectID").combobox('getValue');
                    var contractType = $("#ContractType").combobox('getValue');
                    var year = $("#Year").combobox('getValue');
                    var monthStr = $("#Month").combobox('getValues').toString();
                    var url = '/MonthPlan/GetStatisticalAnalysisDetailList?projectID=' + projectID + '&contractType=' + encodeURI(contractType) + '&year=' + year + '&monthStr=' + monthStr + '&contractID=' + row.ContractID;
                    initDetailTable(url);
                }
                else {
                    initDetailTable();
                }
            }
        });
    }

    function initDetailTable(dataUrl) {
        $('#statisticalAnalysisDetailGrid').datagrid({
            url: dataUrl,
            iconCls: 'icon-bricks',
            nowrap: true,//当数据长度超出列宽时将会自动截取
            autoRowHeight: false,
            striped: true,//设置为true将交替显示行背景
            collapsible: true,
            pagination: true,
            pageSize: 20,
            remoteSort: false,
            singleSelect: true,
            fitColumns: true,
            columns:
            [
                [
                    { title: '父项目名称', field: 'ParentStatisticsItemName', align: 'center', rowspan: 3, width: 100 },
                    { title: '项目名称', field: 'StatisticsItemName', align: 'center', rowspan: 3, width: 100 },
                    { title: '单位', field: 'Unit', align: 'center', rowspan: 3, width: 50 },
                    { title: '总工程量', field: '', width: 100 },
                    { title: '年度计划', field: '', width: 100 },
                    { title: '（对应所选月）计划', field: '', width: 100 },
                    { title: '（对应所选年月）完成', field: '', colspan: 4, width: 400 },
                    { title: '开工累计完成', field: '', colspan: 2, width: 200 }
                ],
                [
                     { title: '金额', field: 'TotalAmount', align: 'center', rowspan: 2, width: 100 },
                     { title: '工程量', field: '', width: 100 },
                     { title: '工程量', field: '', width: 100 },
                     { title: '工程量', field: '', width: 100 },
                     { title: '占总工程量%', field: 'CurrentMonthActualCompletedTotalProportion', align: 'center', rowspan: 2, width: 100 },
                     { title: '占年度计划%', field: 'CurrentMonthActualCompletedYearProportion', align: 'center', rowspan: 2, width: 100 },
                     { title: '占月计划%', field: 'CurrentMonthActualCompletedMonthProportion', align: 'center', rowspan: 2, width: 100 },
                     { title: '工程量', field: '', width: 100 },
                     { title: '占总工程量%', field: 'ConstructionCompletedTotalProportion', align: 'center', rowspan: 2, width: 100 }
                ],
                [
                     { title: '金额', field: 'YearPlanAmount', align: 'center', width: 100 },
                     { title: '金额', field: 'CurrentMonthPlanAmount', align: 'center', width: 100 },
                     { title: '金额', field: 'CurrentMonthActualCompletedAmount', align: 'center', width: 100 },
                     { title: '金额', field: 'ConstructionCompletedAmount', align: 'center', width: 100 }
                ]
            ],
            onLoadSuccess: function (data) {
                if (data.rows.length > 1) {
                    mergeCellsByField("statisticalAnalysisDetailGrid", "ParentStatisticsItemName,StatisticsItemName");
                }
                if (data.rows.length > 0) {
                    mergeColCells("statisticalAnalysisDetailGrid");
                }
            }
        });
    }
</script>

<div class="easyui-layout" style="height:740px;width:2200px;">
    <div data-options="region:'north'" style="height:70px;">
        <table style="margin-top: 5px">
            <tr>
                <td style="width: 95px; text-align: center">项目名称</td>
                <td>
                    <input id="ProjectID" name="ProjectID" class="easyui-combobox" style="width: 180px;" />
                </td>
                <td style="width: 95px; text-align: center">合同类型</td>
                <td>
                    <input id="ContractType" name="ContractType" class="easyui-combobox" style="width: 180px;" />
                </td>
                <td style="width: 50px; text-align: center">年</td>
                <td>
                    <input id="Year" name="Year" class="easyui-combobox" style="width: 80px;" />
                </td>
                <td style="width: 50px; text-align: center">月</td>
                <td>
                    <input id="Month" name="Month" class="easyui-combobox" style="width: 250px;" />
                </td>
            </tr>
            <tr>
                <td style="width: 95px; text-align: center">标段名称</td>
                <td colspan="7">
                    <input id="ContractID" name="ContractID" class="easyui-combobox" style="width: 885px;" />
                    <a href="#" id="btnSearch" class="easyui-linkbutton" data-options="plain:true" onclick="Search();">查看</a>
                </td>
            </tr>
        </table>
    </div>
    <div data-options="region:'center'">
        <div class="easyui-layout" fit="true">
            <div data-options="region:'north'" style="height:200px;">
                <table id="statisticalAnalysisGrid" fit="true"></table>
            </div>
            <div data-options="region:'center'">
                <table id="statisticalAnalysisDetailGrid" fit="true"></table>
            </div>
        </div>
    </div>
</div>
